<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>商城后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/dtree.css}" >
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/font/dtreefont.css}" >
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<span th:replace="common_page::common"></span>

<div class="layui-form layuimini-form">
    <input type="hidden" name="id" id="id" th:value="${model.id}">
    <input type="hidden" name="userMainId" id="userMainId" th:value="${model.userMainId}">
    <input type="hidden" name="messageBodyId" id="messageBodyId" th:value="${model.messageBodyId}">
    <input type="hidden"  id="sendDateString" th:value="${#dates.format(model.sendDate,'yyyy-MM-dd HH:mm:ss')}">

    <div class="layui-form-item">
        <label class="layui-form-label required">消息标题</label>
        <div class="layui-input-block">
            <input type="title" name="title" lay-verify="required" maxlength="255" lay-reqtext="不能为空" placeholder="请输入消息标题" th:value="${model.title}" class="layui-input">
            <tip>填写标题。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">发送时间</label>
        <div class="layui-input-block">
            <input type="title" id="sendDate" name="sendDate" lay-verify="required"  lay-reqtext="不能为空" placeholder="请输入发送时间"   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">消息内容</label>
        <div class="layui-input-block">
            <textarea name="content" class="layui-textarea" maxlength="500" placeholder="请输入消息内容" th:text="${model.content}" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">消息类型</label>
        <div class="layui-input-block">
            <select id="messageTypeCode" name="messageTypeCode"  lay-search="">
                <option th:each="mt : ${messageTypes}" th:value="${mt.code}" th:selected="${mt.code} eq ${model.messageTypeCode}"  th:text="${mt.name}">
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script>
    layui.config({
        base: basePath+'/lib/layui_ext/dtree/' //配置 layui 第三方扩展组件存放的基础目录
    }).use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var laydate = layui.laydate;



        //初始化时间控件
        var sendDate=laydate.render({
            elem: '#sendDate' //指定元素
            ,type: 'datetime'
        });
        sendDate.config.value=$("#sendDateString").val();


        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url:"[[@{/message/messageUser/update}]]",
                contentType: "application/json; charset=utf-8",
                type:'POST',
                data:JSON.stringify(data.field),
                success:function(data){
                    if(data.code<=0) {
                        layer.msg(data.msg);
                        return false;
                    }
                    var index = layer.alert(data.msg, {
                        title: '提示信息'
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);

                    });
                }
            });
            return false;
        });


    });
</script>
</body>
</html>